package drive.Controller;

import drive.Service.ServiceInterface.BaiduService;

import org.codehaus.jettison.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
@RequestMapping("/img")
public class UploadController {

    @Autowired
    BaiduService baiduService;
    //把图片上传到阿里云的接口，会直接返回阿里云的图片url
    @PostMapping("/upload")
    public String upload(MultipartFile file) throws Exception {
        return baiduService.upload(file);
    }

    @PostMapping("/detect")//前端请求type控制识别动物还是植物，url使用阿里云生成的网络图片
    public String detect(String url,String type){
        if(type == "animal"){
            return baiduService.detect(url);
        }else{
            return baiduService.Plant_detect(url);
        }
    }

    @PostMapping("/getkeyword")
    public String getKeyWord(String title,String content) throws JSONException, IOException {
        return baiduService.getKeyWord(title,content);
    }



}

